﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using EBSystem.Enum;
using EBSystem.ViewModels;

namespace EBSystem.Pages
{
    /// <summary>
    /// RegisterPage.xaml 的交互逻辑
    /// </summary>
    public partial class RegisterPage : UserControl
    {
        public RegisterPage()
        {
            InitializeComponent();

            DataContext = new RegisterViewModel();
        }

        private void registerPageReturnButton_Click(object sender, RoutedEventArgs e)
        {
            MainWindow.GetThisMainWindow()?.GotoLoginPage();
        }

        private void registerPageRegisterButton_Click(object sender, RoutedEventArgs e)
        {
            AccountTypeEnum accountType = registerPageComboBox.SelectedIndex switch
            {
                0 => AccountTypeEnum.User,
                1 => AccountTypeEnum.Business,
                2 => AccountTypeEnum.Administrator,
                _ => throw new NotImplementedException()
            };

            if(((RegisterViewModel)DataContext).Register(accountType))
            {
                MessageBox.Show("注册成功");
            }
            else
            {
                MessageBox.Show("注册失败");
            }
        }

        private void registerPasswordBox_PasswordChanged(object sender, RoutedEventArgs e)
        {
            ((RegisterViewModel)DataContext).UserPasswordInput = registerPasswordBox.Password;
            ((RegisterViewModel)DataContext).InputCheck();
        }
    }
}
